<template>
  <div class="tianqi-main">
    <div class="tianqi-zuo">
      <div class="zuo-title tianqi-title">今日天气</div>
      <div class="zuo-content">
        <div class="shang">
          <div class="shangNR">
            <div class="wendu">{{ zuoData.temp }}<span>ºC</span></div>
            <div class="tianqi">{{ zuoData.text }}</div>
            <i class="tianqiIcon" :class="setLeftIcon"></i>
          </div>
        </div>
        <div class="xia">{{ zuoData.windDir+zuoData.windScale }}级</div>
      </div>
    </div>
    <div class="tianqi-you">
      <div class="you-title tianqi-title">近7天天气变化</div>
      <div class="you-content">
        <div class="you-item" v-for="(item,index) in youData" :key="index">
          <div class="you-item-top">{{ item.fxDate.substring(5) }}</div>
          <i class="tianqiIcon" :class="setRightIcon[index]"></i>
          <div class="you-item-bottom">
            {{ item.textDay }}
          </div>
          
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { requestTQ } from '@/api/request.js'
export default {
  name: 'ViewTianqiHF',
  data() {
    return {
      hefengKey: 'a981619d96b54e83a1425eff4e342267',
      cityNo: '101010100',
      zuoData: {},
      youData: []
    }
  },
  mounted() {
    this.getShishi(this.cityNo);
  },
  methods: {
    getShishi(city) {
      requestTQ({
        url: '/weather/now?location='+city+'&key='+this.hefengKey,
        method: 'get'
      }).then(res => {
        this.zuoData = res.data.now;
      });
      requestTQ({
        url: '/weather/7d?location='+city+'&key='+this.hefengKey,
        method: 'get'
      }).then(res => {
        this.youData = res.data.daily;
      })
    }
  },
  computed: {
    setLeftIcon(){
      return "qi-"+this.zuoData.icon+"-fill";
    },
    setRightIcon(){
      let icons = [];
      this.youData.forEach(item => {
        icons.push("qi-"+item.iconDay+"-fill");
      });
      return icons;
    }
  },
  watch: {
    '$store.state': {
      deep: true,
      immediate: false,
      handler() {
        this.$nextTick(()=>{
          console.log(this.$store.state.hefengCityNo);
          this.cityNo = this.$store.state.hefengCityNo;
          this.getShishi(this.cityNo);
        })
      }
    }
  }
}
</script>

<style lang="less" scoped>
.tianqi-main {
  width: 100%;
  height: 80%;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;

  .tianqi-title {
    font-family: siyuanFont;
    font-size: 1.4rem;
    color: @mkColor;
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }

  .tianqi-zuo {
    width: 28%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 0px solid red;

    .zuo-title {
      width: 100%;
      height: 20%;
    }

    .zuo-content {
      width: 100%;
      height: 80%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .shang {
        width: 100%;
        height: 50%;
        display: flex;
        justify-content: flex-start;
        align-items: flex-end;
        color: @tianqiTextColor;
        .shangNR{
          width: 100%;
          height: 40%;
          display: flex;
          justify-content: center;
          align-items: flex-end;
          .wendu {
            font-family: shuziFont;
            font-size: 3rem;
            color: @tianqiWEnduColor;
            span{
              // font-family: shuziFont;
            }
          }
          .tianqi {
            margin-left: 1rem;
            font-size: 1.8rem;
            padding-bottom: 0.4rem;
          }
          .tianqiIcon{
            color: @qWeatherIconColor;
            margin-left: 1rem;
            font-size: 3rem;
            padding-bottom: 0.4rem;
          }
          .qi-100-fill{
            color: #feb41d;
          }
          .qi-101-fill{
            background: linear-gradient(#feb41d 0%,#feb41d 30%,#8adedc 80%);
            background-clip: text;
            -webkit-text-fill-color: transparent;
          }
          .qi-104-fill{
            color: #3475a3;
          }
          .qi-300-fill,.qi-301-fill,.qi-302-fill,.qi-303-fill,.qi-304-fill,.qi-305-fill,.qi-306-fill,.qi-307-fill,.qi-308-fill,.qi-309-fill,.qi-310-fill,.qi-311-fill,.qi-312-fill,.qi-313-fill,.qi-314-fill,.qi-315-fill,.qi-316-fill,.qi-317-fill,.qi-318-fill,.qi-350-fill,.qi-351-fill,.qi-399-fill{
            color: #37fffc;
          }
          .qi-400-fill,        .qi-401-fill,.qi-402-fill,.qi-403-fill,.qi-404-fill,.qi-405-fill,.qi-406-fill,.qi-407-fill,.qi-408-fill,.qi-409-fill,.qi-410-fill,.qi-456-fill,.qi-457-fill,.qi-499-fill{
            color: #ffffff !important;
          }
        }
      }

      .xia {
        width: 100%;
        height: 50%;
        display: flex;
        color: @mkColor;
        font-family: siyuanFont;
        font-size: 1.8rem;
        justify-content: center;
        align-items: center;
      }
    }
  }

  .tianqi-you {
    width: 72%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    border: 0px solid blue;

    .you-title {
      width: 100%;
      height: 20%;
    }

    .you-content {
      width: 100%;
      height: 80%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .you-item{
        width: 13%;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        font-family: siyuanFont;
        font-size: 1.4rem;
        color: @mkColor;
        .you-item-top{
          width: 100%;
          height: 40%;
          display: flex;
          justify-content: center;
          align-items: center;
        }
        .tianqiIcon{
          font-size: 2.6rem;
          margin-left: 0rem;
          color: @qWeatherIconColor;
        }
        .qi-100-fill{
          color: #feb41d;
        }
        .qi-101-fill{
          background: linear-gradient(#feb41d 0%,#feb41d 30%,#8adedc 80%);
          background-clip: text;
          -webkit-text-fill-color: transparent;
        }
        .qi-104-fill{
          color: #3475a3;
        }
        .qi-300-fill,.qi-301-fill,.qi-302-fill,.qi-303-fill,.qi-304-fill,.qi-305-fill,.qi-306-fill,.qi-307-fill,.qi-308-fill,.qi-309-fill,.qi-310-fill,.qi-311-fill,.qi-312-fill,.qi-313-fill,.qi-314-fill,.qi-315-fill,.qi-316-fill,.qi-317-fill,.qi-318-fill,.qi-350-fill,.qi-351-fill,.qi-399-fill{
          color: #37fffc;
        }
        .qi-400-fill,        .qi-401-fill,.qi-402-fill,.qi-403-fill,.qi-404-fill,.qi-405-fill,.qi-406-fill,.qi-407-fill,.qi-408-fill,.qi-409-fill,.qi-410-fill,.qi-456-fill,.qi-457-fill,.qi-499-fill{
          color: #ffffff !important;
        }
        .you-item-bottom{
          width: 100%;
          height: 60%;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
  }
  
}</style>